import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolDemo10 {
    public static void main(String[] args) {
        ThreadFactory factory = new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                return thread;
            }
        };
        // 手动方式创建线程池
        ThreadPoolExecutor executor =
                new ThreadPoolExecutor(5,10,10, TimeUnit.SECONDS,
                        new LinkedBlockingQueue<>(100),factory,
                        new ThreadPoolExecutor.DiscardPolicy());
        for (int i = 1; i < 111; i++) {
            int finalI = i;
            executor.submit(() -> {
                try {
                    Thread.sleep(100 * finalI);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("任务："+finalI+"  "+Thread.currentThread().getName());
            });
        }
        executor.shutdown();
    }
}
